package com.example.webflux.webflux.controller;

import com.example.webflux.webflux.pojo.Student;
import com.example.webflux.webflux.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "/queryById/{id}")
    public Mono<Student> queryById(@PathVariable Long id) {
        Mono<Student> studentMono = studentService.queryById(id);
        return studentMono;
    }
    @RequestMapping(value = "/queryAll")
    public Flux<Student> queryAll() {
        Flux<Student> studentFlux = studentService.queryAll();
        return studentFlux;
    }
    @RequestMapping(value = "/save")
    public Mono<Void> save(@RequestBody Student student) {
        Mono<Student> studentMono = Mono.just(student);
        Mono<Void> save = studentService.save(studentMono);
        return save;
    }
}
